package com.zxjbyte.yiyi.module.system.messaging.consumer;

import com.zxjbyte.yiyi.framework.oss.factory.OssConfigFactory;
import com.zxjbyte.yiyi.framework.redis.listener.AbstractMessageListener;
import com.zxjbyte.yiyi.module.system.util.OptionalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * 文件配置数据刷新Message
 *
 * @Author zhangxingjia
 * @Date 2023/5/15 14:30
 * @Version: 1.0
 */
@Slf4j
@Component
public class OssConfigRefreshConsumer extends AbstractMessageListener<String> {

    public static final String CHANNEL_SYSTEM_OSS_CONFIG_REFRESH = "system.oss_config.refresh";

    @Resource
    private Optional<OssConfigFactory> configFactory;

    @Override
    public void doMessage(String storageCode) {
        log.info("==> executed OSS config refresh message, storageCode: {}", storageCode);
        OptionalUtil.getOssInjectOrThrow(configFactory).reloadRedisCache(storageCode);
    }

    @Override
    public String doChannel() {
        return CHANNEL_SYSTEM_OSS_CONFIG_REFRESH;
    }
}
